package cn.study.zgm.nettyall.channel;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * packageName cn.study.zgm.nettyall.channel
 *
 * @author 你的名字
 * @version JDK 8
 * @className StringGatterChannerWrite (此处以class为例)
 * @date 2025/2/24
 * @description TODO
 */
public class StringGatherChannelWrite {
    public static void main(String[] args) {
        try{
            final ByteBuffer buffer1 = ByteBuffer.wrap("ni".getBytes());
            final ByteBuffer buffer2 = ByteBuffer.wrap("hao".getBytes());
            final ByteBuffer buffer3 = ByteBuffer.wrap("hello".getBytes());
            final FileChannel channel = new RandomAccessFile("gatherWrite.txt", "rw").getChannel();
            final long write = channel.write(new ByteBuffer[]{buffer1, buffer2, buffer3});
            ByteBufferUtil.debugAll(buffer1);
            ByteBufferUtil.debugAll(buffer2);
            ByteBufferUtil.debugAll(buffer3);
        }catch (IOException e){

        }
    }
}
